#include<bits/stdc++.h>
#define ll long long
#define mid ((l+r)>>1)
using namespace std;
namespace IO{
    char buff[1<<21],*p1=buff,*p2=buff;
    char getch(){
        return p1==p2&&(p2=((p1=buff)+fread(buff,1,1<<21,stdin)),p1==p2)?EOF:*p1++;
    }
    template<typename T>
    void read(T &x){
        char ch=getch();int fl=1;x=0;
        while(ch>'9'||ch<'0'){if(ch=='-')fl=-1;ch=getch();}
        while(ch<='9'&&ch>='0'){x=x*10+ch-48;ch=getch();}
        x*=fl;
    }
    template<typename T,typename ...Args>
    void read(T &x,Args& ...args){
        read(x);read(args...);
    }
    char obuf[1<<21],*p3=obuf;
    void putch(char ch){
        if(p3-obuf<(1<<21))*p3++=ch;
        else fwrite(obuf,p3-obuf,1,stdout),p3=obuf,*p3++=ch;
    }
    void pc(const char *s){
    	while(*s)putch(*s),s++;
    }
    char ch[100];
    template<typename T>
    void write(T x){
        if(!x)return putch('0');
        if(x<0)putch('-'),x*=-1;
        int top=0;
        while(x)ch[++top]=x%10+48,x/=10;
        while(top)putch(ch[top]),top--;
    }
    template<typename T,typename ...Args>
    void write(T x,Args ...args){
        write(x),putch(' '),write(args...);
    }
    void flush(){fwrite(obuf,p3-obuf,1,stdout);}
}
using namespace IO;
const int N=2e5+5;
int n;
int dep[N],fa[18][N];
int lca(int x,int y){
	if(dep[x]<dep[y])swap(x,y);
	for(int i=17;i>=0;i--)
		if(dep[fa[i][x]]>=dep[y])x=fa[i][x];
	if(x==y)return x;
	for(int i=17;i>=0;i--)
		if(fa[i][x]!=fa[i][y])
			x=fa[i][x],y=fa[i][y];
	return fa[0][x];
}
inline int dis(int x,int y){return dep[x]+dep[y]-2*dep[lca(x,y)];}
signed main(){
	freopen("forest.in","r",stdin);
	freopen("forest.out","w",stdout);
	int _;read(_,n);
	int a=1,b=1,c=1,d=0;
	int A=1,B=1,D=0;
	for(int i=2;i<=n;i++){
		int x;read(x);
		x^=max(d-1,D);
		dep[i]=dep[x]+1;
		fa[0][i]=x;
		for(int j=1;j<=17;j++)
			fa[j][i]=fa[j-1][fa[j-1][i]];
		int d1=(dis(b,i)+dis(c,i)+dis(b,c))/2;
		int d2=(dis(a,i)+dis(c,i)+dis(a,c))/2;
		int d3=(dis(a,i)+dis(b,i)+dis(a,b))/2;
		int maxn=max({d,d1,d2,d3});
		if(maxn==d){
			
		}else if(maxn==d1){
			a=i;
		}else if(maxn==d2){
			b=i;
		}else if(maxn==d3){
			c=i;
		}
		d=maxn;
		d1=dis(A,i),d2=dis(B,i);
		maxn=max({D,d1,d2});
		if(maxn==D){
			
		}else if(maxn==d1){
			B=i;
		}else if(maxn==d2){
			A=i;
		}
		D=maxn;
		write(max(d-1,D)),putch('\n');
	}
	return flush(),0;
}

